#tag Class
Class CFData
Inherits CFType
Implements CFPropertyList
	#tag Event
		Function ClassID() As CFTypeID
		  return me.ClassID
		End Function
	#tag EndEvent


	#tag Method, Flags = &h0
		Sub Constructor(theData as MemoryBlock)
		  // This one also takes Strings. No need for an extra constructor taking Strings therefore
		  
		  #if targetMacOS
		    soft declare function CFDataCreate lib CarbonLib (allocator as Ptr, bytes as Ptr, length as Integer) as Ptr
		    
		    if not (theData is nil) then
		      if theData.Size < 0 then
		        // this comes from a Ptr - you need to use the CFType constructor with the additional Boolean parm!
		        raise new TypeMismatchException
		      end if
		      
		      super.Constructor CFDataCreate(nil, theData, theData.Size), true
		    end if
		  #endif
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		 Shared Function ClassID() As CFTypeID
		  #if targetMacOS
		    declare function TypeID lib CarbonLib alias "CFDataGetTypeID" () as UInt32
		    static id as CFTypeID = CFTypeID(TypeID)
		    return id
		  #endif
		End Function
	#tag EndMethod


	#tag ComputedProperty, Flags = &h0
		#tag Getter
			Get
			#if targetMacOS
			soft declare function CFDataGetLength lib CarbonLib (theData as Ptr) as Integer
			soft declare sub CFDataGetBytes lib CarbonLib (theData as Ptr, range as CFRange, buffer as Ptr)
			
			if not me.IsNULL then
			dim dataLength as Integer = CFDataGetLength(me.Reference)
			if dataLength > 0 then
			dim m as new MemoryBlock(dataLength)
			dim range as CFRange = CFRangeMake(0, dataLength)
			CFDataGetBytes me.Reference, range, m
			return m
			end if
			end if
			#endif
			
			return new MemoryBlock(0)
			End Get
		#tag EndGetter
		Data As MemoryBlock
	#tag EndComputedProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Description"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="CFType"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
